using System.Collections.Generic;
using BSDS.Commands.Commands.Implementation;
using BSDS.Core.Model.Services;

namespace BSDS.Commands.Commands.Creation.Implementation
{
    public class ListCommandCreator : CommandCreatorBase
    {
        private readonly AccountService accountService;

        public ListCommandCreator(AccountService accountService)
        {
            this.accountService = accountService;
        }

        protected override bool Supports(Dictionary<string, string> parameters)
        {
            return parameters.Count >= 1 && parameters.ContainsKey("list");
        }

        protected override ICommand Create(Dictionary<string, string> parameters)
        {
            bool showDetails;
            string dataSourceName;

            if (parameters.ContainsKey("datasource"))
            {
                showDetails = true;
                dataSourceName = parameters["datasource"];
            }
            else
            {
                showDetails = false;
                dataSourceName = string.Empty;
            }

            return new ListCommand(accountService, showDetails, dataSourceName);
        }
    }
}